package com.ruoyi.project.business.nativedevice.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.nativedevice.request.ListNativeDeviceRequest;
import com.ruoyi.project.business.nativedevice.response.NativeDeviceResponse;
import com.ruoyi.project.business.nativedevice.service.INativeDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备入网记录Controller
 *
 * @author ${author}
 * @date 2024-07-26
 */
@RestController
@RequestMapping("/business/nativedevice")
public class NativeDeviceController extends BaseController {
    @Autowired
    private INativeDeviceService nativeDeviceService;

    /**
     * 查询设备入网记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:nativedevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListNativeDeviceRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<NativeDeviceResponse> list = nativeDeviceService.selectNativeDeviceList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出设备入网记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:nativedevice:export')")
    @Log(title = "设备入网记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListNativeDeviceRequest request) {
        Long tenantId = getTenantId();
        List<NativeDeviceResponse> list = nativeDeviceService.selectNativeDeviceList(request, tenantId);
        ExcelUtil<NativeDeviceResponse> util = new ExcelUtil<>(NativeDeviceResponse.class);
        return util.exportExcel(list, "nativedevice");
    }

    /**
     * 获取设备入网记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:nativedevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(nativeDeviceService.selectNativeDeviceById(id));
    }
}
